package com.teaphy.coroutinecrawler.flow.operators.terminal

import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*

fun main() = runBlocking {

    println("runBlocking context: ${currentCoroutineContext()}, thread name: ${Thread.currentThread().name}")

    val scope = CoroutineScope(CoroutineName("AAA") + Dispatchers.IO)

    val job = flowOf(1, 2, 3)
        .onEach {
            println("onEach - context: ${currentCoroutineContext()} , thread name: ${Thread.currentThread().name}")
        }.onStart {
            println("onStart - context: ${currentCoroutineContext()}, thread name: ${Thread.currentThread().name} ")
        }
        .onCompletion {
            println("onCompletion - context: ${currentCoroutineContext()} , thread name: ${Thread.currentThread().name}")
        }.launchIn(scope)

    delay(5000)
    println("Done")
}